package com.pipayshop.service.impl;


import com.pipayshop.domain.StoreCategoryMin;
import com.pipayshop.domain.dto.StoreInfoMinListByConditionDTO;
import com.pipayshop.domain.vo.IndexShopInfoVO;
import com.pipayshop.domain.vo.PageDataVO;
import com.pipayshop.mapper.PhysicalStoreCategoryMinMapper;
import com.pipayshop.mapper.PhysicalStoreInfoMapper;
import com.pipayshop.service.PhysicalStoreCategoryMinService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pipayshop.mapper.ImageMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author wzx
 */
@Service
public class PhysicalStoreCategoryMinServiceImpl extends ServiceImpl<PhysicalStoreCategoryMinMapper, StoreCategoryMin> implements PhysicalStoreCategoryMinService {

    @Resource
    private PhysicalStoreCategoryMinMapper shopCategoryMinMapper;

    @Resource
    private PhysicalStoreInfoMapper shopInfoMapper;

    @Resource
    private ImageMapper imageMapper;

    @Override
    public List<StoreCategoryMin> getShopCategoryMinList(String categoryPid) {
        List<StoreCategoryMin> shopCategoryMins = shopCategoryMinMapper.selectList(new QueryWrapper<StoreCategoryMin>().
                eq("del_flag", 0).eq("category_pid", categoryPid));
        for (StoreCategoryMin shopCategoryMin : shopCategoryMins) {
            shopCategoryMin.setCategoryImg(imageMapper.selectPath(shopCategoryMin.getCategoryImg()));
        }
        return shopCategoryMins;
    }

    /**
     * 实体店二级分类标签列表对应的店铺列表条件分页展示
     */
    @Override
    public PageDataVO getShopInfoMinListByCondition(StoreInfoMinListByConditionDTO shopInfoMinListByConditionDTO) {
        // 获取总条数
        Integer indexShopInfoVOCount = shopInfoMapper.getIndexShopInfoVOCount(shopInfoMinListByConditionDTO.getCategoryId(), shopInfoMinListByConditionDTO.getRegionId(),shopInfoMinListByConditionDTO.getShopName());
        List<IndexShopInfoVO> indexShopInfoVO = shopInfoMapper.getShopInfoMinListByCondition(shopInfoMinListByConditionDTO.getCategoryId(), (shopInfoMinListByConditionDTO.getPages() - 1) * shopInfoMinListByConditionDTO.getLimit(), shopInfoMinListByConditionDTO.getLimit(), shopInfoMinListByConditionDTO.getRegionId(),shopInfoMinListByConditionDTO.getShopName());
        return new PageDataVO(indexShopInfoVOCount,indexShopInfoVO);
    }

}
